package cn.itcast.asdasd;

import java.util.Arrays;

public class UtilityClass {
    public static void affiche (double t [ ] [ ]){
        for (double i[]:t)
            for (double j:i)
                System.out.printf("%f ",j);
    }
    public static boolean regulier (double t [ ] [ ]){
        int last=t[0].length;
        for (double i[]:t)
            if(i.length!=last) return false;
        return true;
    }
    public static double [ ] sommeLignes (double t [ ] [ ]){
        double tmp[]=new double[t.length];
        for (int i = 0; i < t.length; i++)
            for (int j = 0; j < t[i].length; j++)
                tmp[i]+=t[i][j];
        return tmp;
    }
    public static double [ ] [ ] somme (double [ ] [ ] t1, double [ ] [ ] t2){
        if(t1.length!=t2.length)return null;
        double tmp[][]=new double[t1.length][];
        for (int i = 0; i < t1.length; i++) {
            if (t1[i].length!=t2[i].length)return null;
            tmp [i]=new double[t1[i].length];
            for (int j = 0; j < t1[i].length; j++)
                tmp[i][j]=t1[i][j]+t2[i][j];
        }
        return tmp;
    }
    public static void main(String[] args) {
        double a[][]={{1,2,3},{2,5}};
        double aa[][]={{1,2,3,4},{2,3}};
        UtilityClass.affiche(a);
        System.out.println(UtilityClass.regulier(a));
        System.out.println(Arrays.toString(sommeLignes(a)));
        System.out.println(Arrays.deepToString(somme(a,a)));
        System.out.println(Arrays.deepToString(somme(a,aa)));
    }
}